//
//  PopOverViewController.swift
//  微博
//
//  Created by 段瑞金 on 16/5/12.
//  Copyright © 2016年 段瑞金. All rights reserved.
//

import UIKit
//创建一个负责管理自定义转场动画的控制器
class PopOverViewController: UIPresentationController {
    
    //MARK:-懒加载一个覆盖按钮
    //当点击这个按钮的时候,会让弹出的view消失
    private lazy var coverButton = UIButton()

    override init(presentedViewController: UIViewController, presentingViewController: UIViewController)
    {
        super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)

        
    }
    
    override func presentationTransitionWillBegin() {
        //设置按钮的尺寸及位置
        coverButton.backgroundColor = UIColor(white: 0.7, alpha: 0.5)
        coverButton.frame = containerView!.bounds
        containerView?.addSubview(coverButton)
        //给按钮添加监听
        coverButton.addTarget(self, action: #selector(PopOverViewController.coverButtonClicked), forControlEvents: .TouchUpInside)
    }
    //覆盖按钮的监听点击
   @objc private func coverButtonClicked () -> (){
        RJLOG("")
    presentedViewController.dismissViewControllerAnimated(true, completion: nil)

    }
    
    /// 即将布局存放在容器视图上的子控件时调用
    /// 和UIView一样, 在该方法中布局子控件
    override func containerViewWillLayoutSubviews() {
        
        /*
        通过当前对象的containerView属性可以获取容器视图
        通过当前对象的presentedView()方法, 可以获取被弹出的控制器的view
        */
        
        presentedView()?.frame = CGRect(x: 100, y: 56, width: 200, height: 200)
    }

}
